//
//  DebugAppInfoViewController.m
//  YK_DebugManager
//
//  Created by edward on 2021/2/24.
//

#import "DebugAppInfoViewController.h"
#import "DebugAppInfoCell.h"
#import "DebugAppInfoUnit.h"

@interface DebugAppInfoViewController ()<UITableViewDelegate,UITableViewDataSource>

///
@property(nonatomic,strong) UITableView *tableView;

@end

@implementation DebugAppInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"应用信息";
    [self.view addSubview:self.tableView];
    // Do any additional setup after loading the view.
}

#pragma mark -tableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [DebugAppInfoUnit sharedInstance].infoList.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSArray *array = [DebugAppInfoUnit sharedInstance].infoList[section][@"array"]?:@[];
    return array.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DebugAppInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(DebugAppInfoCell.class)];
    if (!cell) {
        cell = [[DebugAppInfoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(DebugAppInfoCell.class)];
        cell.backgroundColor = UIColor.clearColor;
        cell.contentView.backgroundColor = UIColor.clearColor;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    NSDictionary *dic = [DebugAppInfoUnit sharedInstance].infoList[indexPath.section][@"array"][indexPath.row]?:@{};
    [cell setTitle:dic[@"title"]?:@"" detail:dic[@"value"]?:@""];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 55;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    NSString *title = [DebugAppInfoUnit sharedInstance].infoList[section][@"title"]?:@"";
    return title;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

- (UITableView *)tableView
{
    if(!_tableView)
    {
        UITableView *tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
        if (@available(iOS 15.0, *)) {
            tableView.sectionHeaderTopPadding = 0;
        }
        tableView.dataSource = self;
        tableView.delegate = self;
        tableView.estimatedRowHeight = 85;
        tableView.rowHeight = UITableViewAutomaticDimension;
        tableView.backgroundColor = UIColor.clearColor;
        tableView.showsVerticalScrollIndicator = NO;
        tableView.showsHorizontalScrollIndicator = NO;
//        [tableView registerClass:UITableViewCell.class forCellReuseIdentifier:NSStringFromClass(UITableViewCell.class)];
        _tableView = tableView;
    }
    return _tableView;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
